//线段树-剪枝(势能线段树)
//有些区间修改操作是无法懒下来的

#include <iostream>
#include <cmath>
using namespace std;
typedef long long ll;
#define lc p << 1
#define rc p << 1 | 1
const int N = 1e5 + 10;
ll a[N];
struct node
{
    int l, r;
    ll sum, max;
}tr[N << 2];

void pushup(int p)
{
    tr[p].sum = tr[lc].sum + tr[rc].sum;
    tr[p].max = max(tr[lc].max, tr[rc].max);
}

void build(int p, int l, int r)
{
    tr[p] = {l, r, a[l], a[l]}; 
    if(l == r) return;
    int mid = (l + r) >> 1;
    build(lc, l, mid); build(rc, mid + 1, r);
    pushup(p);
}

void modify(int p, int x, int y)
{
    if(tr[p].max == 1) return; //剪枝
    int l = tr[p].l, r = tr[p].r;
    if(l == r)
    {
        tr[p].sum = sqrt(tr[p].sum);
        tr[p].max = sqrt(tr[p].max);
        return;
    }
    int mid = (l + r) >> 1;
    if(x <= mid) modify(lc, x, y); 
    if(y > mid) modify(rc, x, y);
    pushup(p); 
}

ll query(int p, int x, int y)
{
    int l = tr[p].l, r = tr[p].r;
    if(x <= l && r <= y) return tr[p].sum;
    ll sum = 0;
    int mid = (l + r) >> 1;
    if(x <= mid) sum += query(lc, x, y);
    if(y > mid) sum += query(rc, x, y);
    return sum;
}

int main()
{
    int n, m; cin >> n;
    for(int i = 1; i <= n; i++) cin >> a[i];
    cin >> m;
    build(1, 1, n);
    while(m--)
    {
        int k, l, r; cin >> k >> l >> r;
        if(l > r) swap(l, r);
        if(k == 0)
        {
            modify(1, l, r);
        }
        else
        {
            cout << query(1, l, r) << endl;
        }
    }
    return 0;
}